home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / MacUserProj / MacUser Projects / June / 2GenApp Src / MenuUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-25  |  4.3 KB  |  164 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             MenuUtil.c
  3.     
  4.     DESCRIPTION:     Menu Utilities
  5.  
  6.     AUTHOR:            Kurt W.G. Matthies
  7.         
  8.     Copyright © 1990 by Code of the West, Inc., All Rights Reserved.
  9.  
  10.     
  11.     Revision History:
  12.     ==========================================================
  13.     4.24.90 -    June 1990 MacUser Release: No Changes
  14.     3.30.90    -    May 1990 MacUser Release
  15.     ==========================================================
  16.  
  17.    ***************************************************************************** */
  18. #include "AppGlobals.h"
  19. #include "MenuConstants.h"
  20.  
  21. #include "AboutBoxPr.h"
  22. #include "DocUtilPr.h"
  23. #include "ShellPr.h"
  24. #include "WindowUtilPr.h"
  25.  
  26. #include "MenuUtilPr.h"
  27.  
  28. /* ---------------------  Local Prototypes  -------------------------------- */
  29. void            doAppleMenu            ( short );
  30. void            doFileMenu            ( short );
  31. void            doEditMenu            ( short );
  32.  
  33. /* -----------------------------------------------------------------------------
  34.     doMenu -        determine what item in which menu was selected.
  35.     3.30.9090kwgm    route control to the action function
  36. -------------------------------------------------------------------------------*/
  37. void 
  38. doMenu (menuResult)
  39.     long          menuResult;
  40. {
  41.     short         menuID, itemNumber;
  42.  
  43.     menuID = HiWord (menuResult);        /* which menu */
  44.     itemNumber = LoWord (menuResult);    /* what item */
  45.     
  46.     switch (menuID) 
  47.     {
  48.         case kAppleMenuID:
  49.             doAppleMenu (itemNumber);
  50.             break;
  51.             
  52.         case kFileMenuID:
  53.             doFileMenu (itemNumber);
  54.             break;
  55.             
  56.         case kEditMenuID:
  57.             doEditMenu (itemNumber);
  58.             break;
  59.             
  60.     }
  61.         
  62.     HiliteMenu (0);
  63.  
  64. }    /* doMenu */
  65.  
  66. /* -----------------------------------------------------------------------------------
  67.     doFileMenu -    file menu item routing function
  68.     3.30.90kwgm
  69. -------------------------------------------------------------------------------------- */
  70. static void 
  71. doFileMenu (theItem)
  72.     short    theItem;
  73. {
  74.     switch (theItem) 
  75.     {
  76.         case kNewItem:
  77.             doNewDoc ();
  78.             break;
  79.             
  80.         case kCloseItem:
  81.             doCloseDoc (FrontWindow ());
  82.             break;
  83.             
  84.         case kQuitItem:
  85.             cleanExit (true);
  86.             break;
  87.     }
  88.     
  89. } /* doFileMenu */
  90.  
  91. /* -----------------------------------------------------------------------------------
  92.     doAppleMenu -    apple menu item routing function
  93.     3.30.90kwgm
  94. -------------------------------------------------------------------------------------- */
  95. static void 
  96. doAppleMenu (theItem)
  97.     short        theItem;
  98. {
  99.     Str255        itemName;
  100.     
  101.     if (theItem == 1)
  102.          doAboutBox ();
  103.     else
  104.     {    /* desk accesories get called here */
  105.         GetItem (GetMHandle (kAppleMenuID), theItem, itemName);
  106.         OpenDeskAcc (itemName);
  107.     }
  108.     
  109. } /* doAppleMenu */
  110.  
  111. /* -----------------------------------------------------------------------------------
  112.     doEditMenu -     edit menu item routing function.
  113.     3.30.90kwgm        Supplied for desk accessory compatibility
  114. -------------------------------------------------------------------------------------- */
  115. static void 
  116. doEditMenu (theItem)
  117.     short    theItem;
  118. {
  119.     SystemEdit (theItem);        /* for desk accessories */
  120. } /* doEditMenu */
  121.  
  122. /* ----------------------------------------------------------------------------------
  123.     fixMenus -        fixup the applications menus 
  124.     3.30.90kwgm
  125. ------------------------------------------------------------------------------------- */
  126. void
  127. fixMenus ()
  128. {
  129.     DocPtr        theDoc;
  130.     
  131.     theDoc = FrontWindow();
  132.     
  133.     if (theDoc)        /* if there's an open document */
  134.     {
  135.         EnableItem (gFileMenu, kCloseItem);        /* enable the close item */
  136.         
  137.         if (((WindowPeek) theDoc)->windowKind  >= 1)    /* generic's window */
  138.         {
  139.             DisableItem (gEditMenu, kUndoItem);        /* generic doesn't use the edit menu */
  140.             DisableItem (gEditMenu, kCutItem);        /* so it disables the items */
  141.             DisableItem (gEditMenu, kCopyItem);
  142.             DisableItem (gEditMenu, kPasteItem);
  143.             DisableItem (gEditMenu, kClearItem);
  144.         }
  145.         else
  146.         {
  147.             EnableItem (gEditMenu, kUndoItem);        /* DAs can use the edit menu */
  148.             EnableItem (gEditMenu, kCutItem);
  149.             EnableItem (gEditMenu, kCopyItem);
  150.             EnableItem (gEditMenu, kPasteItem);
  151.             EnableItem (gEditMenu, kClearItem);
  152.             EnableItem (gFileMenu, 0);
  153.         }
  154.     }
  155.     else
  156.     {
  157.         EnableItem (gFileMenu, kNewItem);
  158.         DisableItem (gFileMenu, kCloseItem);        /* no open windows, so no need to close */
  159.     }
  160. } /* fixMenus */
  161.  
  162. /* ===============================  EOF  =======================================
  163.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  164. ================================================================================ */